package com.intramirror.product.algorithm;

import com.intramirror.product.entity.AggregateRuleType;
import com.intramirror.product.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created on 2018/1/30.
 * @author 123
 */
@Service
public class AggregateFactory {

    @Autowired
    IAggregateAlgorithm matchFromOne;
    @Autowired
    IAggregateAlgorithm matchFromTwo;
    @Autowired
    IAggregateAlgorithm matchFromExists;

    public IAggregateAlgorithm getAggregateAlgorithm(AggregateRuleType ruleType) throws BusinessException {
        IAggregateAlgorithm aggregateAlgorithm;
        switch (ruleType) {
        case MATCH_FROM_TWO:
            aggregateAlgorithm = matchFromTwo;
            break;
        case MATCH_FROM_ONE:
            aggregateAlgorithm = matchFromOne;
            break;
        case MATCH_FROM_EXISTS_SPU:
            aggregateAlgorithm = matchFromExists;
            break;
        default:
            throw new BusinessException("Not support rule type " + ruleType.toString());
        }
        return aggregateAlgorithm;
    }
}
